from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from cart import  models
# from course import courseser,models as coursemodels
# class CourserSeria(ModelSerializer):
#     class Meta:
#         model = coursemodels.CourseModel
#         fields = ['cname','price','cover','discount']
#
#
# class CartSerializer(ModelSerializer):
#     course = CourserSeria()#嵌套序列化器
#     class Meta:
#         model = models.CartModel
#         fields = '__all__'
#
#
# class CartSer(ModelSerializer):
#     class Meta:
#         model = models.CartModel
#         fields = '__all__'

class CartSerializer(ModelSerializer):
    courselist=serializers.SerializerMethodField(read_only=True)
    def get_courselist(self,obj):
        return {"level":obj.course.level,"id":obj.course.id,"cname":obj.course.cname,"discount":obj.course.discount,"price":obj.course.price,"cover":str(obj.course.cover)}
    class Meta:
        model = models.CartModel
        fields = '__all__'
